package com.modifiertech.lineage.commands;

import com.modifiertech.lineage.Lineage;
import com.modifiertech.lineage.api.LineageModAccess;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.text.TextComponentBase;
import net.minecraftforge.fml.common.FMLCommonHandler;

public class CmdHelper {

    public static void execServerCommand(EntityPlayer entityPlayer, String command){
        FMLCommonHandler.instance().getMinecraftServerInstance()
                .commandManager.executeCommand(entityPlayer.getServer(),command);
    }

    public static void execClientSay(TextComponentBase textComponents){
    	if(!LineageModAccess.isClientSide()) {
    		return;
    	}
        try{
            Minecraft.getMinecraft().player.sendMessage(textComponents);
        }catch (Exception e){
            Lineage.logger.error(e.getMessage());
        }
    }


    public static void execServerSay(TextComponentBase textComponents){
        try{
            FMLCommonHandler.instance().getMinecraftServerInstance()
                    .getPlayerList().sendMessage(textComponents);
        }catch (Exception e){
            Lineage.logger.error(e.getMessage());
        }
    }

    public static boolean ifExecAsSilent(String[] args){
        if(null==args|| 0==args.length)return false;
        for(int i=0;i<args.length;i++){
            if(args[i].contains("[SILENT]")){
                args[i].replace("[SILENT]","");
                return true;
            }
        }
        return false;
    }
    public static String[] cutSilentCmd(String[] args){
        for(int i=0;i<args.length;i++){
            if(args[i].contains("[SILENT]")){
                args[i].replace("[SILENT]","");
            }
        }
        return args;
    }


}
